<?php
	date_default_timezone_set('Australia/Sydney');

	$complaint = $_POST['complaint'];
	$userID = $_POST['userID'];
	$firstname = "";
	$surname = "";
	$age = "";
	$phone = "";
	$address = "";
	$crossStreet = "";
	$email = "";
	$refNum = 23123123;
	$time = time();
	$geolocation = 3242;
	//
	//	Utilise this later for adding timestamps to table
	//
	//$hour = time() / 3600 % 24;
    //$minute = time() / 60 % 60;

    //
    //	Mailing code use in this or registration needs a mailing server to work
    //
	//$subject = $refNum . '/' . $surname . '/' . $age . '/' . $phone;
	//$message = $hour . ':' . $minute . '/' . $firstname . ' ' . $surname . '/' . $address . '/' . $complaint . '#' . $crossStreet;
	//if(isset($refNum) && isset($firstname) && isset($age) && isset($phone) && isset($address) && isset($complaint) && isset($crossStreet) && isset($email))
	//{
		//mail("ccorscadden118@gmail.com", "successful POST", "foo");
		//mail($email, $subject, $message);
	if($complaint != "" && $userID != "")
		connect_database();
	else
		echo "<p>Input Missing</p>";
	//}
	//else
		//mail("ccorscadden118@gmail.com", "failed POST", "foo");


	function connect_database(){
		$mysqli = new mysqli('localhost', 'root', '', 'gluphien');
		//echo $DBConnect;
		if ($mysqli->connect_errno)
			echo "<p>Connection Failed.</p>";
		//
		//	TODO: get user details add to complaint then generate refNum and add to request table
		// 
		$SQLstring = "INSERT INTO `request` (`userID`, `complaint`, `time`, `geolocation`) 
			VALUES ('" . $GLOBALS["userID"] . "', '" . $GLOBALS["complaint"] . "', '" . $GLOBALS["time"] . "', '" . $GLOBALS["geolocation"] . "')";
		//echo "<p>" . $SQLstring . "</p>";
		//echo $GLOBALS["userID"];
		if (mysqli_query($mysqli, $SQLstring) === TRUE) {
			echo "<p>success users</p>";
		}
		else
		{
			echo $mysqli->error;
		}
		$mysqli->close();
	}
